home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6114 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: access4.digex.net!not-for-mail
  2. From: ell@access4.digex.net (Ell)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pure Virtual Destructor Question
  5. Date: 10 Feb 1996 18:57:40 GMT
  6. Organization: The Universe
  7. Message-ID: <4fipr4$f71@news4.digex.net>
  8. References: <4fas7a$7ns@comet2.magicnet.net>
  9. NNTP-Posting-Host: access4.digex.net
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Jody Hagins (gamecox@magicnet.magicnet.net) wrote:
  13. : Assume a class Foo s.t.
  14. : class Foo
  15. : {
  16. : public:
  17. :   virtual ~Foo() = 0;
  18. : };
  19. : inline Foo::~Foo()
  20. : {
  21. :   // do some destructor stuff
  22. : }
  23. :
  24. : This is correct, and compiles fine.  
  25.  
  26. Right.
  27.  
  28. : However, I get a warning:
  29. : "foo.h", : warning: please provide an out-of-line definition:  
  30. : Foo::~Foo() {}; 
  31. : which is needed by derived classes
  32.  
  33. I don't get warning this with VC++ 1.5.
  34.  
  35. : Even when I make it non inline (in foo.C) I still get it.  The only way
  36. : I can think of to get around the problem is to do it right in the declaration
  37. : itself.  However, the compiler barks at both
  38. : class Foo
  39. : {
  40. : public:
  41. :   virtual ~Foo() { /* do some stuff */ } = 0;
  42. : };
  43. : and
  44. : class Foo
  45. : {
  46. : public:
  47. :   virtual ~Foo() = 0 { /* do some stuff */ }
  48. : };
  49.  
  50. Pretty sure you can not declare a pure virtual function within a class and
  51. supply a definition for it _within_ the class it is declared in.  So while
  52. a pure virtual may have a definition, the definition itself must be
  53. physically outside the class. 
  54.  
  55. The nice thing about this is that you can keep the class from being
  56. instantiated, simply by using a pure virtual dtor.  Yet the dtor may have
  57. the same functionality as a non-pure virtual dtor. 
  58.  
  59. How about that folks?  ;)
  60.  
  61. Elliott
  62.